$(".threeChoose .threeTab").bind("click", function(event) {
	// parent.$("iframe")[0].style.height = "97vw";
  event.stopPropagation();
  if (
    $(this)
      .attr("class")
      .indexOf("active") == -1
  ) {
    if ($(".threeChoose .active").length > 0) {
      $($(".threeChoose .active").find(".threeImg")).attr(
        "src",
        "../../static/images/salesman/nochoose.png"
      );
      $(".threeChoose .active").removeClass("active");
    }
    $(this).addClass("active");
    $($(this).find(".threeImg")).attr(
      "src",
      "../../static/images/salesman/onchoose.png"
    );
  } else {
    $($(".threeChoose .active").find(".threeImg")).attr(
      "src",
      "../../static/images/salesman/nochoose.png"
    );
    $(".threeChoose .active").removeClass("active");
  }

  if (
    $(this)
      .attr("class")
      .indexOf("tabLocation") != -1
  ) {
    if (
      $(".threeChoose .threeLian")
        .css("display")
        .indexOf("none") != -1
    ) {
      $(".threeChoose .threeLian").css("display", "flex");
			// parent.$("iframe")[0].style.height = "97vw";
			$(".shopsell").css({'display':'none'});
			$('#mjchoose').css({'display':'none'});
			$('#pricechoose').css({'display':'none'});
      $(".threeLian .threeRow .threeCon:first").addClass("active");
			$(".threeLian .threeMiddle").empty();
			$(".threeLian .threeRight").empty();
      $.ajax({
        type: "POST",
        dataType: "json",
        url: "../../static/public/china.json",
        success: function(result) {
          china = result;
					$(".otherinst").remove();
          for (var i in result) {
            $(".threeChoose .threeLian .threeLeft").append(
              '<div class="threeRow otherinst" location="' +
                result[i].name +
                '" onclick="findCity(this)"><div class="threeCon"><span>' +
                result[i].name +
                "</span></div></div>"
            );
          }
        }
      });
    } else {
      $(".threeChoose .threeLian").css("display", "none");
			// parent.$("iframe")[0].style.height = "14vw";
    }
  }
});
var china;
var province;
$(function() {});
function findCity(that) {
  var location = $(that).attr("location");
  if (location == "不限" || location == "全部地区") {
    confirmArea(that);
  } else {
    $(".threeChoose .threeLian .threeMiddle .threeRow").remove();
    $(".threeChoose .threeLian .threeRight .threeRow").remove();
    $(".threeChoose .threeLian .threeMiddle").append(
      '<div class="threeRow" location="不限" onclick="findArea(this)"><div class="threeCon active"><span>不限</span></div></div>'
    );
    for (var i in china) {
      if (china[i].name == location) {
        for (var j in china[i].child) {
          $(".threeChoose .threeLian .threeMiddle").append(
            '<div class="threeRow" location="' +
              china[i].child[j].name +
              '" onclick="findArea(this)"><div class="threeCon"><span>' +
              china[i].child[j].name +
              "</span></div></div>"
          );
        }
      }
    }
    province = location;
    $(".threeChoose .threeLian .threeLeft .active").removeClass("active");
    $($(that).find(".threeCon")).addClass("active");
  }
}
function findArea(that) {
  var location = $(that).attr("location");
  if (location == "不限" || location == "全部地区") {
    confirmArea(that);
  } else {
    $(".threeChoose .threeLian .threeRight .threeRow").remove();
    $(".threeChoose .threeLian .threeRight").append(
      '<div class="threeRow" location="不限" onclick="findArea(this)"><div class="threeCon active"><span>不限</span></div></div>'
    );
    for (var i in china) {
      if (china[i].name == province) {
        for (var j in china[i].child) {
          if (china[i].child[j].name == location) {
            for (var s in china[i].child[j].child) {
              $(".threeChoose .threeLian .threeRight").append(
                '<div class="threeRow" location="' +
                  china[i].child[j].child[s] +
                  '" onclick="confirmArea(this)"><div class="threeCon"><span>' +
                  china[i].child[j].child[s] +
                  "</span></div></div>"
              );
            }
          }
        }
      }
    }
    $(".threeChoose .threeLian .threeMiddle .active").removeClass("active");
    $(that).addClass("active");
  }
}
function confirmArea(that) {
  $(".threeChoose .tabLocation .threeCon").text($(that).attr("location"));
  if (
    $(that)
      .attr("class")
      .indexOf("active") == -1
  ) {
    $($(that).find(".threeCon")).addClass("active");
  }
  $(".threeChoose .threeLian").css("display", "none");
	// parent.$("iframe")[0].style.height = "14vw";
}

//阻止冒泡，点击三级联动外隐藏元素
$(document).click(function() {
  $(".threeChoose .threeLian").hide();
});
$(".threeChoose .threeLian").on("click", function(event) {
  event.stopPropagation();
});
